<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>回调式ref</title>
  <!--  引入React核心库-->
  <script src="https://unpkg.com/react@18/umd/react.development.js"></script>
  <!--  引入react-dom,用于支持React操作Dom-->
  <script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
  <!-- 引入babel，用于将jsx转为js-->
  <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
  <script src="https://unpkg.com/prop-types@15.6.2/prop-types.js"></script>

</head>

<body>
  <!-- 准备一个容器 -->
  <div id="root"></div>

  <script type="text/babel">
    // 1.创建组件
    class Demo extends React.Component {
      showData = () => {
        console.log(this.refs);
        alert(this.input1.value)
      }
      render() {
        return (
          <div>
            <input ref={currentNode => { this.input1 = currentNode }} type="text" placeholder='点击按钮提示数据' />
            <button onClick={this.showData} >点我提示左侧的数据</button>
          </div>
        )
      }
    }

    // 2.渲染组件到页面
    const container = document.getElementById('root')
    const root = ReactDOM.createRoot(container)
    root.render(<Demo />)
  </script>
</body>

</html>